# Contributor: Nathan Johnson <nathan@nathanjohnson.info>
# Maintainer: Nathan Johnson <nathan@nathanjohnson.info>
pkgname=libcouchbase
pkgver=3.3.11
pkgrel=0
pkgdesc="C client library for Couchbase"
url="https://developer.couchbase.com/community"
arch="all"
license="Apache-2.0"
depends_dev="
	openssl-dev>3
	snappy-dev
	"
makedepends="
	$depends_dev
	cmake
	libev-dev
	libevent-dev
	libtool
	libuv-dev
	perl
	samurai
	zlib-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-utils
	$pkgname-doc
	$pkgname-libevent
	$pkgname-libev
	$pkgname-libuv
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/couchbase/libcouchbase/archive/$pkgver.tar.gz
	fix_socktest.patch
	"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DLCB_NO_MOCK=ON \
		-DLCB_SKIP_GIT_VERSION=ON
	cmake --build build
}

check() {
	cd "$builddir"/build
	ctest -j1 -E 'check-(select|libevent|libev|libuv)-sock-tests'
}

package() {
	 DESTDIR="$pkgdir" cmake --install build
}

dev() {
	default_dev
	mv "$subpkgdir"/usr/bin/cbc-write-config \
		"$pkgdir"/usr/bin
	rmdir "$subpkgdir"/usr/bin
}

libevent() {
	pkgdesc="$pkgdesc (libevent backend)"
	depends="$pkgname=$pkgver-r$pkgrel"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libcouchbase/libcouchbase_libevent.so "$subpkgdir"/usr/lib
}

libev() {
	pkgdesc="$pkgdesc (libev backend)"
	depends="$pkgname=$pkgver-r$pkgrel"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libcouchbase/libcouchbase_libev.so "$subpkgdir"/usr/lib
}

libuv() {
	pkgdesc="$pkgdesc (libuv backend)"
	depends="$pkgname=$pkgver-r$pkgrel"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libcouchbase/libcouchbase_libuv.so "$subpkgdir"/usr/lib
}

utils() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends="$pkgname=$pkgver-r$pkgrel"
	provides="$pkgname-bin=$pkgver-r$pkgrel"

	amove usr/bin
}

sha512sums="
0bec02bd55d722f5f8bf525a71b56f4b391bed7b18f3e363b0f82bd64fbcfb05e7e429a18387ff245afd4b52bc76c91b52bf17960b4271886e132444a35d3de2  libcouchbase-3.3.11.tar.gz
72319b86fdd91728723ccb091e72199788a84e2ec9ea12c0fcd1ed686eb155ec11e0addbff96735f83e7f31764a85650f0483b6e76d3a8bee16f71b2751fe4a9  fix_socktest.patch
"
